Skip to content

[db] MySQL: Set --explicit-defaults-for-timestamp=OFF #4226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 17, 2021

Conversation

geropl
Copy link
Member

@geropl geropl commented May 17, 2021

Fixes #4169.

This PR contains two commits:

  • the first is the actual fix
  • the other is a cleanup that has no compile/runtime impact. It just reduces the diff between our TypeORM config and our migrations.

Copy link
Contributor

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for fixing this @geropl! 💯

Code looks good to me, and fixes the problem:

  • SELECT @@GLOBAL.explicit_defaults_for_timestamp; now gives the correct value
  • I can manually start prebuilds in your deployment

I've just noticed a few inconsistencies around the ON UPDATE being present in our database but not in your new default params (not sure if it has an impact, but probably better to be 100% aligned with the DB). I've reported all inconsistencies as in-line suggestions.

// DROP all input values as they are set by the DB 'ON UPDATE'/ as default value.
// We're relying on the system variable explicit-defaults-for-timestamp here (link: https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp):
// `undefined` get's converted to NULL, which on the DB is turned into the configured default value for the column.
// In our case, that's 100% CURRENT_TIMESTAMP.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd prefer being super-explicit here, in order to not leave any room for confusion

Suggested change
// In our case, that's 100% CURRENT_TIMESTAMP.
// In our case, that's 100% CURRENT_TIMESTAMP(6).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think precision 6 we only have for part of them, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -20,6 +20,7 @@ export class DBSnapshot implements Snapshot {
@Column({
type: 'timestamp',
precision: 6,
default: () => 'CURRENT_TIMESTAMP(6)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the ON UPDATE CURRENT_TIMESTAMP(6) also be part of this?

Suggested change
default: () => 'CURRENT_TIMESTAMP(6)',
default: () => 'CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)',

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creationTime should only be updated on creation I guess, not when the row get's updated (that's what ON UPDATE CURRENT_TIMESTAMP does).

TBH I did not - but propably should have - cross-verified this with the actual DB columns but judged from the meaning....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geropl I'm happy to align this the other way around then, by removing the ON UPDATE CURRENT_TIMESTAMP(6) from the DB where you don't set them.

Would that make sense?

@@ -31,6 +31,7 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace {
@Column({
type: 'timestamp',
precision: 6,
default: () => 'CURRENT_TIMESTAMP(6)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here:

Suggested change
default: () => 'CURRENT_TIMESTAMP(6)',
default: () => 'CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)',

@@ -33,13 +33,15 @@ export class DBAppInstallation implements AppInstallation {
@Column({
type: 'timestamp',
precision: 6,
default: () => 'CURRENT_TIMESTAMP(6)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question:

Suggested change
default: () => 'CURRENT_TIMESTAMP(6)',
default: () => 'CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)',

Co-authored-by: Jan Keromnes <[email protected]>
@geropl geropl merged commit cae15f3 into main May 17, 2021
@geropl geropl deleted the gpl/mysql-timestamp-defaults branch May 17, 2021 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent MySQL settings in preview environments and staging/production
2 participants